package com.api.regression.group.creategroupfolder;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.api.test.AssertApi;
import com.api.test.UrnType;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.ObjectResultApi;

@ContextConfiguration(locations = { "classpath:/group/group-context.xml" })
public class CreateGroupFolder extends AbstractApiTest {

	@Value("#{editgroups['user.groupEditor'].appId}")
	private String userUrn;

	@Value("#{editgroups['user.groupEditor'].password}")
	private String userPassword;

	@Value("#{editgroups['group.editor.urn']}")
	private String groupUrn;

	private String createdFolderUrn = "";

	@BeforeClass
	protected void loginUser() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test
	public void testGetGroup() throws ZyncroApiException {

		String name = "Folder new Namee";
		String description = "Folder Descripton";

		ObjectResultApi<String> result = getApi().getService(IGroupApiService.class).createFolder(groupUrn, name, description);

		AssertApi.assertUrnType(result.getObject(), UrnType.DOCUMENT);

		createdFolderUrn = result.getObject();
	}

	@AfterClass
	public void restoreValues() throws ZyncroApiException {
		getApi().getService(IGroupApiService.class).deleteDocument(groupUrn, createdFolderUrn);
	}
}
